/*
切片追加与截取 - 追加
liuyang: 大概可以看出来，slice就是Java中的ArrayList
追加 append
https://www.bilibili.com/video/BV1gf4y1r79E/?p=14&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
*/
package main

import "fmt"

func info(numbers []int) {
	fmt.Printf("len = %d, cap = %d, slice = %v\n", len(numbers), cap(numbers), numbers)
}

func main() {
	// 1. cap
	var numbers = make([]int, 3, 5)
	//fmt.Println("len = %d, cap = %d, slice = %v\n", len(numbers), cap(numbers), numbers)
	info(numbers)

	// 向numbers切片追加一个元素1
	numbers = append(numbers, 1)
	info(numbers)
	numbers = append(numbers, 1)
	info(numbers)
	numbers = append(numbers, 1)
	info(numbers) // “神奇”的一幕发生了！！

	// 2. 看看默认的make
	fmt.Println("======================")
	var numbers2 = make([]int, 3)
	//var numbers2 = make([]int, 4) // 试一下，对比输出可看出规律。
	numbers2 = append(numbers2, 1)
	info(numbers2)
	numbers2 = append(numbers2, 1)
	info(numbers2)
	numbers2 = append(numbers2, 1)
	info(numbers2) // “神奇”的一幕发生了！！
}
